<template>
	<view class="passenger-flow">
		<!-- <v-gap /> -->
		<!-- <view class="con-3 ">
			<view class="con-3_left ">{{itemChooselist.venue_name}}</view>
			<view class="con-3_right " @click="show_no">切换</view>
		</view> -->
		<view class="con-1">
			<nav-bar title="客流统计" color="white" bg="rgba(0,0,0,0)"></nav-bar>
			<view class="bg">
				<view class="address">
					<view class="flex-space-between">
						<view class="flex-align">
							<van-image v-if="itemChooselist.venue_thumb != ''" width="74rpx" height="74rpx" radius="2"
								style="margin-right: 10rpx;" :src="itemChooselist.venue_thumb" />
							<van-image v-else width="74rpx" height="74rpx" radius="10rpx" fit="cover" style="margin-right: 10rpx;" src="https://img.yzcdn.cn/vant/cat.jpeg" />
							<view>
								<view class="address-name">{{itemChooselist.venue_name}}</view>
								<view class="address-desc">地址:{{itemChooselist.address}}</view>
							</view>
						</view>
						<view class="exchange flex-center flex-column " @click="show_no">
							<van-icon name="exchange" size="16" />
							切换
						</view>
					</view>
				</view>
			</view>

		</view>
		<view style="width: 100%; height: 60rpx;background-color: #f8f8f8;margin-top: 300rpx;">
			<view style="float: left;">
				<image style="width: 32rpx;height: 32rpx;margin-top: 15rpx;margin-left: 30rpx;"
					src="https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/dbe7a7371520f7585b4a83558336c24acbace2cc.png"
					mode=""></image>
			</view>
			<view style="float: left;line-height: 60rpx;font-size: 28rpx;color: #aaaaaa;margin-left: 20rpx;">
				数据仅供参考，以后台财务数据为准
			</view>
		</view>
		<view class="module1">
			<van-row class="text-center">
				<van-col :span="8">
					<view class="value">{{week_num}}</view>
					<view class="label">本周客流</view>
				</van-col>
				<van-col :span="8">
					<view class="value red">{{history_num}}</view>
					<view class="label">最高记录</view>
				</van-col>
				<van-col :span="8">
					<view class="value">{{month_num}}</view>
					<view class="label">本月客流</view>
				</van-col>
			</van-row>

			<view class="title" style="margin-top: 40rpx;">客流特征分析</view>
			<view style="height: 200px" v-show="showlist">
				<qiun-data-charts type="pie" :opts="pieOpts" :chartData="pieChartData" />
				<!-- <qiun-data-charts type="pie" :chartData="pieChartData"/> -->
			</view>
		</view>

		<v-gap />

		<view class="module2">
			<van-row class="dates text-center">
				<van-col v-for="item in dates" :key="item.value" :span="6">
					<view class="date-item" :class="{ active: dateActive === item.value }" @click="dataslist(item)">
						{{ item.name }}
					</view>
				</van-col>
			</van-row>
			<!-- <u-tabs :list="dates" @click="click"></u-tabs> -->

			<view class="title" style="margin-top: 40rpx;">客流量分析</view>
		</view>
		<view v-show="showlist">
			<!-- <qiun-data-charts type="line" :opts="lineOpts" :chartData="lineChartData" /> -->
			<qiun-data-charts type="line" canvasId="scrolllineid"
				:opts="{enableScroll:true,xAxis:{scrollShow:true,itemCount:4,disableGrid:true}}"
				:chartData="lineChartData" :ontouch="true" :canvas2d="true" />
		</view>
		<van-popup closeable :show="show" round position="bottom" get-container="body" @close="showclose"
			:z-index='9999'>
			<view class="good-box">
				<view class="title">
					切换场馆
				</view>
				<view class="good-list">
					<!-- <van-radio-group :value="radio" @change="onChange"> -->
						<view class="good-item" v-for="(item,index) in venuelist" :key="index" @click="onChangelist(item)">
							<!-- <van-radio :name="index" :value="index" color="#2f75fa"
								:checked="index == 0 ? true : false"> -->
								<view class="flex-align">
									<van-image width="124rpx" height="124rpx" radius="10rpx" fit="cover"
										v-if="item.venue_thumb != ''" :src="item.venue_thumb" />
									<van-image v-else width="124rpx" height="124rpx" radius="10rpx" fit="cover"
										src="https://img.yzcdn.cn/vant/cat.jpeg" />
									<!-- <view class="info">
										<view class="name">{{item.venue_name}}</view>
										<view class="flex-align">
											<view class="tag">票务</view>
											<view class="tag">篮球</view>
											
										</view>
										
										<view class="address">{{item.address}}</view>
									</view> -->
									<view class="info">
										<view class="name">{{item.venue_name}}</view>
										<view class="flex-align" v-if="item.project_list != ''">
											<view class="tag" v-if="item.project_list[0].name != ''">
												{{item.project_list[0].name}}
											</view>
											<view class="tag" v-if="item.project_list[1].name != '' && item.project_list[1]">
												{{item.project_list[1].name}}
											</view>
											<view class="tag" v-if="item.project_list[2].name != ''&& item.project_list[2]">
												{{item.project_list[2].name}}
											</view>
										</view>
										<view class="address">{{item.address}}</view>
									</view>
								</view>
							<!-- </van-radio> -->
						</view>
					<!-- </van-radio-group> -->
				</view>

			<!-- 	<view class="footer">
					<view class="btn" @click="queren">确认</view>
				</view> -->
			</view>
		</van-popup>
	</view>
</template>

<script>
	const personal = require("@/api/personal/index.js");
	export default {
		data() {
			return {
				pieOpts: {
					color: ['rgb(145,213,255)', 'rgb(255,163,158)'],
					extra: {
						pie: {
							borderWidth: 1
						}
					},
					legend: {
						position: 'right'
					},
					dataLabel: false
				},
				pieChartData: {},
				dates: [{
						name: '今日',
						value: '5'
					},
					{
						name: '本周',
						value: '6'
					},
					{
						name: '本月',
						value: '7'
					},
					{
						name: '本年',
						value: '8'
					},
				],
				dateActive: '5',
				lineOpts: {
					color: ['rgb(255,116,32)', 'rgb(71,199,162)'],
					legend: {
						position: 'top'
					},
					"padding": [0, 10, 0, 15],
					"xAxis": {
						axisLineColor: 'rgb(229,229,229)',
						"disableGrid": true,
						fontColor: 'rgb(153,153,153)',
					},
					"yAxis": {
						gridColor: 'rgb(229,229,229)',
						data: [{
							fontColor: 'rgb(153,153,153)',
							title: '单位(人)'
						}],
						showTitle: true
					}
				},
				lineChartData: {},
				show: false,
				venuelist: [], //场馆列表
				itemChoose: {}, // 场馆数据
				itemChooselist: {}, // 场馆数据
				showlist: true,
				week_num: '', //本周客流
				month_num: '', //本月客流
				history_num: '', //历史客流
				nac: ''
			}
		},
		onLoad() {
			if (uni.getStorageSync("entry_name") == '') {
				uni.showToast({
					title: '请登录！',
					icon: 'exception',
					duration: 850
				});
				setTimeout(() => {
					uni.navigateTo({
						url: '/pages/my-center/my-center'
					})
				}, 1000);
			}
			var data = uni.getStorageSync("wqzdy");
			var items = JSON.parse(data)
			this.venuelist = items
			this.itemChooselist = this.venuelist[0]
			this.index_index()
		},
		methods: {
			async index_index() {
				// uni.showLoading({
				// 	title: "加载中",
				// 	mask: true,
				// });
				let params = {
					venue_id: this.itemChooselist.id,
				};
				let res = await personal.index_index(params);
				if (res.code == 1) {
					this.lineChartData = res.data.lineChartData
					this.pieChartData = res.data.pieChartData
					this.week_num = res.data.week_num //本周客流
					this.month_num = res.data.month_num //本月客流
					this.history_num = res.data.history_num //历史客流
					// uni.hideLoading();
				}
			},
			dataslist(item) {
				this.dateActive = item.value
				this.nac = item.value
				this.analyse()
			},

			async analyse() {
				// uni.showLoading({
				// 	title: "加载中",
				// 	mask: true,
				// });
				let params = {
					venue_id: this.itemChooselist.id,
					sourceTab: this.nac
				};
				let res = await personal.analyse(params);
				if (res.code == 1) {
					this.lineChartData = res.data.lineChartData
					// uni.hideLoading();
				}
			},
			click(item) {
			},
			// 选择场馆
			onChange(e) {
				let that = this
				let i = e.detail
				const item = this.venuelist[i]
				if (item) {
					this.itemChoose = item
					this.venuelist[i].checked = true
				} else {
					this.itemChoose = {}
				}
			},
			onChangelist(item){
				this.itemChoose = item
				this.lineChartData = []
				this.itemChooselist = this.itemChoose
				this.show = false
				this.showlist = true
				this.dateActive = '5'
				this.nac = '5'
				this.index_index()
			},
			// 确认按钮
			queren() {
				this.lineChartData = []
				this.itemChooselist = this.itemChoose
				this.show = false
				this.showlist = true
				this.dateActive = '5'
				this.nac = '5'
				this.index_index()
			},
			show_no() {
				this.show = true
				this.showlist = false
			},
			showclose() {
				this.show = false
				this.showlist = true
			}
		}
	}
</script>

<style lang="scss" scoped>
	.passenger-flow {
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		background-color: rgb(243, 243, 243);
		padding: 0rpx 0 50rpx 0;
		position: relative;

		.con-1 {
			width: 100%;
			position: relative;

			/deep/ .nav-bar {
				position: fixed;
				z-index : 999;
			}

			.bg {
				width: 100%;
				height: 300rpx;
				background-image: url("https://jiangsudiantuo2022.oss-cn-hangzhou.aliyuncs.com/img/5d1ccc3b7ac6cc185130c88a8ac2e90b1eeba707.png");
				background-size: 100%;
				background-position: 50% 80%;
				position: fixed;
				z-index : 9;

				.address {
					color: #fff;
					padding-top: 190rpx;
					padding-right: 30rpx;
					padding-left: 30rpx;
					height: 150rpx;

					&-name {
						font-size: 34rpx;
						font-weight: 700;
						line-height: 34rpx;
					}

					&-desc {
						margin-top: 18rpx;
						font-size: 22rpx;
						line-height: 22rpx;
					}

					.exchange {
						width: 100rpx;
						height: 100rpx;
						border-radius: 50%;
						background-color: rgba(0, 0, 0, 0.2);
						color: rgb(234, 248, 248);
						font-size: 24rpx;
					}
				}
			}
		}

		/deep/ .good-box {
			height: 60vh;
			padding: 0px 30rpx;
			display: flex;
			flex-direction: column;

			.title {
				color: #000;
				font-size: 30rpx;
				font-weight: 700;
				margin-top: 40rpx;
			}

			.van-radio__label {
				line-height: inherit;
			}

			.good-list {
				flex: 1;
				height: 0;
				overflow: auto;

				.good-item {
					margin-top: 30rpx;

					.info {
						margin-left: 25rpx;

						.address {
							color: #fff;
							padding-top: 20rpx;
							padding-right: 30rpx;
							height: 70rpx;

							&-name {
								font-size: 34rpx;
								font-weight: 700;
								line-height: 34rpx;
							}

							&-desc {
								margin-top: 18rpx;
								font-size: 22rpx;
								line-height: 22rpx;
							}

							.exchange {
								width: 100rpx;
								height: 100rpx;
								border-radius: 50%;
								background-color: rgba(0, 0, 0, 0.2);
								color: rgb(234, 248, 248);
								font-size: 24rpx;
							}
						}

						.name {
							color: rgb(51, 51, 51);
							font-size: 30rpx;
							font-weight: 500;
							margin-bottom: 10rpx;
						}


						.tag {
							color: rgb(4, 179, 90);
							font-size: 24rpx;
							font-weight: 500;
							padding: 0px 10rpx;
							margin-right: 20rpx;
							background-color: rgba(4, 179, 90, 0.2);
							border-radius: 4rpx;

							&:nth-of-type(2) {
								color: rgb(236, 70, 246);
								background-color: rgba(236, 70, 246, 0.2);
							}
						}

						.address {
							margin-top: 10rpx;
							color: rgb(136, 136, 136);
							font-size: 22rpx;
						}
					}

				}
			}

			.footer {
				padding: 20rpx 0;
				background-color: rgb(255, 255, 255);

				.btn {
					color: rgb(255, 255, 255);
					font-size: 30rpx;
					font-weight: 700;
					padding: 20rpx 0;
					text-align: center;
					background-image: linear-gradient(0deg, rgb(99, 93, 247) 0%, rgb(165, 173, 246) 100%);
					border-radius: 60rpx;
				}
			}
		}

		.con-3 {
			width: 100%;
			height: 80rpx;
			background-color: rgb(248, 248, 248);
			color: rgb(51, 51, 51);
			font-size: 28rpx;
			font-weight: 700;

			.con-3_left {
				float: left;
				line-height: 80rpx;
				margin-left: 29rpx;
			}

			.con-3_right {
				float: right;
				line-height: 80rpx;
				color: rgb(90, 101, 255);
				margin-right: 29rpx;
			}
		}

		.module1 {
			padding: 40rpx 30rpx;

			.value {
				font-size: 44rpx;
				font-weight: 700;
				line-height: 33rpx;
			}

			.label {
				margin-top: 19rpx;
				font-size: 28rpx;
				font-weight: 700;
				line-height: 28rpx;
			}
		}

		.title {
			font-size: 28rpx;
			font-weight: 700;
		}

		.module2 {
			padding: 20rpx 40rpx;

			.dates {
				color: rgb(136, 136, 136);
				font-size: 28rpx;
				font-weight: 700;

				.date-item {
					padding: 20rpx 0;
				}

				.active {
					color: rgb(51, 51, 51);
				}
			}
		}
	}
</style>
